import { getTenantID, onMouseOutBtn } from '@/utils';
import { Button, Form, InputNumber, Select } from 'antd';
import Cls from 'classnames';
import { FormInstance } from 'antd/es/form/Form';
import { DeleteOutlined } from '@ant-design/icons';
import { ILoadMapTypeAll } from '@/common';
import { useState } from 'react';
import _ from 'lodash';

/** 抽取专家 表格配置项 */
export const getExtractTableConfig = (
  delMaterialCallback: (resObj: Record<string, any>, index: number) => void,
  loadMapInfo: Record<string, any>,
  mapLoading: boolean,
  unitList: Array<Record<string, any>>,
  disIDs,
  setDisIDs,
  selectKeyMap,
  onSelectKey,
): Record<string, any>[] => {
  const tableConfig: Record<string, any>[] = [
    {
      title: <div style={{ textAlign: 'center' }}>从事专业</div>,
      dataIndex: 'industryType',
      key: 'industryType',
      visible: true,
      width: 180,
      render: (_text: string, _record: any, index: any) => {
        return (
          <Form.Item name={['extractTable', index, 'industryType']} rules={[{ required: true, message: '请选择从事专业' }]}>
            <Select
              placeholder="请选择从事专业"
              loading={mapLoading}
              showSearch
              filterOption={(input, option: any) => (option?.children ?? '').toLowerCase().includes(input.toLowerCase())}
              onSelect={(val) => onSelectKey(val, index, _record)}
            >
              {loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.EXPERTS_INDUSTRY_TYPE}`]?.map((item: any) => {
                return (
                  <Select.Option key={item?.id} value={item?.id} disabled={disIDs?.indexOf(item?.id) != -1}>
                    {item?.name}
                  </Select.Option>
                );
              })}
            </Select>
          </Form.Item>
        );
      },
    },
    {
      title: <div style={{ textAlign: 'center' }}>人数</div>,
      dataIndex: 'count',
      key: 'count',
      visible: true,
      width: 120,
      render: (_text: string, _record: any, index: any) => {
        return (
          <Form.Item name={['extractTable', index, 'count']} rules={[{ required: true, message: '请输入人数' }]}>
            <InputNumber placeholder="请输入" min={1} />
          </Form.Item>
        );
      },
    },
    {
      title: <div style={{ textAlign: 'center' }}>屏蔽单位</div>,
      dataIndex: 'companyNames',
      key: 'companyNames',
      visible: true,
      width: 120,
      render: (_text: string, _record: any, index: any) => {
        return (
          <Form.Item name={['extractTable', index, 'companyNames']}>
            <Select mode="multiple" allowClear style={{ width: '100%' }} placeholder="选择屏蔽单位" options={unitList || []} />
          </Form.Item>
        );
      },
    },
    {
      title: <div style={{ textAlign: 'center' }}>操作</div>,
      dataIndex: 'otherBtn',
      key: 'otherBtn',
      visible: true,
      width: 100,
      render: (_text: string, _record: any, index: any) => {
        return (
          <div className="counterpoartDelBtnStyle">
            <Button
              type="link"
              icon={<DeleteOutlined />}
              className={Cls('manageBtntTxtStyle')}
              onMouseOut={onMouseOutBtn}
              onClick={() => delMaterialCallback(_record, index)}
            >
              清除
            </Button>
          </div>
        );
      },
    },
  ];

  return tableConfig;
};
